Remove mention that 1-bit images use 1 byte per pixel#8777
Remove mention that 1-bit images use 1 byte per pixel#8777hchargois wants to merge 1 commit intopython-pillow:mainfrom hchargois:patch-1
Conversation
|
Internally, storage for 1 bit images is 1 byte per pixel: Pillow/src/libImaging/Storage.c Lines 64 to 67 in d7d48df 1 bit images are shuffled at import/export to put them in this format. |
|
Interesting! I didn't expect
That documentation also says to look at And in any case, I still think the two sentences (the "one pixel per byte" and the "tobytes returns raw data") are very misleading when taken together. I would still suggest to remove the first sentence. I think it's better to not give any expectations than provide false expectations. |
|
Yeah, I suspect that the 1 bit thing is just one of those historical choices -- it's a lot easier to do math in 1 pixel per byte than one per bit, especially when you already have that math implemented for other modes. Historically it's tripped up people with the array/numpy integration, and this is effectively the one way you can get 1 bit/pixel out of a mode |
The origin of this sentence was in #1470, where one user wanted to clarify that i think ‘raw image data' is intended to mean one-dimensional pixel data without context, and ‘from the internal storage’ is intended to mean ‘this isn’t the form the data had in any given file’
As a general principle, I'm in favour of clarifying information. I'm not in favour of removing information because it might be misunderstood. I think 'stored with one pixel per byte' is meant to communicate that Pillow will use more memory than you might expect. This is kind of a specific situation to document - not so much because of the 1 mode, but because what you’re talking about just the “raw” encoder, and And interestingly, when this specific situation does become relevant to Pillow's internal code, there is a comment that tries to explain your scenario. Lines 730 to 735 in c8d98d5 I've created #8878 as an alternative - it leaves in the information about how mode 1 image data is stored, mentions that |
|
Great, thank you. I'll close this PR in favor of the new one. |
That line in the documentation implies that a 1-bit (W, H)-sized image would occupy W*H bytes in raw form, at least that's how I understand it.
But it doesn't seem to be the case in Pillow 11.1.0:
It seems that it now stores strips of (up to) 8 horizontal pixels. Since that line in the documentation was last edited 12 years ago, I guess it was true at the time but the format has been changed for efficiency since. Which is great, but the documentation is misleading.
I suggest to simply remove the 1-byte-per-pixel part.